/**
 * @author Tobias Boehm
 *
 * 22.03.2011
 */
package org.anddev.andengine.extension.tbsengine.region;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Vector;

import org.anddev.andengine.extension.tbsengine.match.gamestate.AbsGlobalGameState.IGameStateElement;

import android.graphics.Region;

/**
 * @author Tobias Boehm
 *
 */
public class RegionController implements IGameStateElement {

	private final HashMap<Class<? extends Region>, Vector<Region>> mTypeSortedRegions;
	private final HashMap<Class<? extends Region>, HashSet<IRegionChangedListener>> mRegionChangedListeners;
	
	public RegionController(){
		
		this.mTypeSortedRegions = new HashMap<Class<? extends Region>, Vector<Region>>();
		this.mRegionChangedListeners = new HashMap<Class<? extends Region>,  HashSet<IRegionChangedListener>>();
	}
	
	public boolean registerRegionChangedListener(final Class<? extends Region> pRegionType, final IRegionChangedListener pRegionChangedListener){
				
		if(this.mRegionChangedListeners.containsKey(pRegionType)){
			
			return this.mRegionChangedListeners.get(pRegionType).add(pRegionChangedListener);
			
		}else{
			
			HashSet<IRegionChangedListener> listenerSet = new HashSet<RegionController.IRegionChangedListener>();
			
			listenerSet.add(pRegionChangedListener);
			
			this.mRegionChangedListeners.put(pRegionType, listenerSet);
		
			return true;
		}
	}
	
	public boolean unregisterRegionChangedListener(final Class<? extends Region> pRegionType, final IRegionChangedListener pRegionChangedListener){
		
		if(this.mRegionChangedListeners.containsKey(pRegionType)){
			
			return this.mRegionChangedListeners.get(pRegionType).remove(pRegionChangedListener);
			
		}else{
								
			return false;
		}
	}
	
	public interface IRegionChangedListener{
		
	};
	
}
